package br.enovar.com.dois;

import java.util.GregorianCalendar;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Teste {

	/**
	 * @param args
	 * @throws SystemException 
	 * @throws HeuristicRollbackException 
	 * @throws HeuristicMixedException 
	 * @throws RollbackException 
	 * @throws SecurityException 
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Configuration configuration = new Configuration();
		configuration.configure();
		
		SessionFactory sf = configuration.buildSessionFactory();
		Session s = sf.openSession();
		
		Fornecedor f = new Fornecedor();
		f.setNome("mario");
		
		ContaPagar cp = new ContaPagar();
		//relacionamento
		cp.setId(3L);
		cp.setFornecedor(f);
		cp.setDescricao("Papel A4");
		cp.setData(new GregorianCalendar());
		cp.setValor(12858.0);
		
		s.beginTransaction();
		f.setNome("mario");
		s.save(cp);
		s.save(f);
		f.setNome("bruno");
		s.save(f);
		cp.setDescricao("hsgf");
		s.merge(cp);
		s.getTransaction().commit();
		
	}

}
